package com.fuhailiu.opengl.renders;

import android.content.Context;
import android.view.MotionEvent;

import com.fuhailiu.opengl.utils.LogUtil;
import com.fuhailiu.opengl.view.GLViewGroup;
import com.fuhailiu.opengl.widget.GLTriangleStrip;

public class RenderTriangleStrip extends AbsRender {

	private final String TAG = getClass().getSimpleName();

	private GLTriangleStrip mGLTriangleStrip = null;

	public RenderTriangleStrip(Context context) {
		super(context);
	}

	@Override
	protected GLViewGroup makeWorld(Context context) {
		LogUtil.LogD(TAG, "makeWorld   <---");

		GLViewGroup layout = new GLViewGroup(context);

		mGLTriangleStrip = new GLTriangleStrip(context, 0.5f, 0.2f, 36);
		layout.addView(mGLTriangleStrip);

		LogUtil.LogD(TAG, "makeWorld   --->");

		return layout;
	}

	// 最后一次触摸点坐标
	private float mLastTouchX;
	private float mLastTouchY;

	// 角度缩放比例
	private final float TOUCH_SCALE_FACTOR = 180.0f / 320;

	@Override
	public void onTouchEvent(MotionEvent event) {
		float x = event.getX();
		float y = event.getY();

		switch (event.getAction()) {
		case MotionEvent.ACTION_DOWN:
			break;

		case MotionEvent.ACTION_MOVE:
			float deltaX = x - mLastTouchX;
			float deltaY = y - mLastTouchY;
			mGLTriangleStrip.mAngleX += deltaY * TOUCH_SCALE_FACTOR;
			mGLTriangleStrip.mAngleY += deltaX * TOUCH_SCALE_FACTOR;
			break;

		case MotionEvent.ACTION_UP:
		case MotionEvent.ACTION_CANCEL:
			break;
		}

		mLastTouchX = x;
		mLastTouchY = y;
	}

}
